home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / Cell Control / DATA1.CAB / VCDEMO_Files / FormulaDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-11  |  2.8 KB  |  113 lines

  1. // FormulaDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "VCDemo.h"
  6. #include "FormulaDlg.h"
  7.  
  8. #include <afxpriv.h>
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CFormulaDlg dialog
  18.  
  19.  
  20. CFormulaDlg::CFormulaDlg(CWnd* pParent /*=NULL*/)
  21.     : CDialog(CFormulaDlg::IDD, pParent)
  22. {
  23.     //{{AFX_DATA_INIT(CFormulaDlg)
  24.     m_exprstr = _T("A3+B3+C3");
  25.     m_result = _T("");
  26.     //}}AFX_DATA_INIT
  27. }
  28.  
  29.  
  30. void CFormulaDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32.     CDialog::DoDataExchange(pDX);
  33.     //{{AFX_DATA_MAP(CFormulaDlg)
  34.     DDX_Control(pDX, IDC_SGCTRL1, m_ctrl);
  35.     DDX_Text(pDX, IDC_EDIT_EXPR, m_exprstr);
  36.     DDX_Text(pDX, IDC_EDIT_RESULT, m_result);
  37.     //}}AFX_DATA_MAP
  38. }
  39.  
  40.  
  41. BEGIN_MESSAGE_MAP(CFormulaDlg, CDialog)
  42.     //{{AFX_MSG_MAP(CFormulaDlg)
  43.     ON_BN_CLICKED(IDC_BUTTON_CALC, OnButtonCalc)
  44.     ON_BN_CLICKED(IDC_BUTTON_EXPRHELP, OnButtonExprhelp)
  45.     //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CFormulaDlg message handlers
  50.  
  51. BOOL CFormulaDlg::OnInitDialog() 
  52. {
  53.     CDialog::OnInitDialog();
  54.     
  55.     // TODO: Add extra initialization here
  56.     m_ctrl.DoSetCellString( 0,1, "January" );
  57.     m_ctrl.DoSetCellString( 1,1, "February" );
  58.     m_ctrl.DoSetCellString( 2,1, "March" );
  59.     m_ctrl.DoSetCellString( 3,1, "first quarter" );
  60.     m_ctrl.DoSetCellString( 4,1, "total year" );
  61.  
  62.     m_ctrl.DoSetCellValue( 0,2, 567.5 );
  63.     m_ctrl.DoSetCellValue( 1,2, 679.3 );
  64.     m_ctrl.DoSetCellValue( 2,2, 368.3 );
  65.  
  66.     m_ctrl.DoSetFormula( 3,2, "a3+b3+c3" );
  67.     m_ctrl.DoSetFormula( 4,2, "d3*4" );
  68.  
  69.     m_ctrl.SetPageLabelVisible( FALSE );
  70.     COleVariant var( "VCDEMO" );
  71.     m_ctrl.DoSetMessageTitle( var );
  72.     return TRUE;  // return TRUE unless you set the focus to a control
  73.                   // EXCEPTION: OCX Property Pages should return FALSE
  74. }
  75.  
  76. void CFormulaDlg::OnButtonCalc() 
  77. {
  78.     // TODO: Add your control notification handler code here
  79.     USES_CONVERSION;      //add #include <afxpriv.h> in your stdafx.h
  80.  
  81.     UpdateData();
  82.     if( !m_exprstr.IsEmpty() ){
  83.         short type;
  84.         char buf[40];
  85.         COleVariant var;
  86.         if( m_ctrl.DoCalculateExpr( m_exprstr, &type, &var ) ){
  87.             if( type == 0 ){
  88.                 sprintf( buf, "%G", var.dblVal );
  89.                 m_result = CString( "value: ")+buf;
  90.             }
  91.             else if( type == 1 ){
  92.                 m_result = CString( "string: ")+W2A(V_BSTR(&var));;
  93.             }
  94.             else if( type == 2 ){
  95.                 m_result = CString( "cell: ")+W2A(V_BSTR(&var));;
  96.             }
  97.             else if( type == 3 ){
  98.                 m_result = CString( "area: ")+W2A(V_BSTR(&var));;
  99.             }
  100.             UpdateData( FALSE );
  101.         }
  102.         else{
  103.             AfxMessageBox( "Syntax!" );
  104.         }
  105.     }
  106. }
  107.  
  108. void CFormulaDlg::OnButtonExprhelp() 
  109. {
  110.     // TODO: Add your control notification handler code here
  111.     AfxMessageBox( "    CELL support 4 data types: double value,  string, cell, area. " );
  112. }
  113.